Skip to content

Conversation

@romankurnovskii
Copy link
Owner

@romankurnovskii romankurnovskii commented Dec 15, 2025

Summary by Sourcery

Add multiple new LeetCode-style problem solutions and accompanying explanations for selected problems.

New Features:

  • Add English explanations for problems 2482, 797, and 237 describing problem restatements, strategies, and walkthroughs.
  • Introduce initial solution implementations for several problems including spiral matrix from linked list, garden watering taps, BST from preorder, recovering contaminated tree elements, arithmetic subarray checking, ones-minus-zeros matrix, vowel sorting in strings, minimal Fibonacci decomposition, linked-list node deletion, all paths from source to target in a DAG, tile sequence counting, tournament champion detection, matrix restoration from row and column sums, minimal character changes between anagram strings, identifying row with maximum ones, decomposing a number into three consecutive integers, and the Josephus-style winner problem.

Summary by CodeRabbit

  • New Features
    • Added 19 new algorithm solution implementations (various data structures and greedy/graph/matrix problems).
  • Documentation
    • Added ~20 detailed explanation articles with problem restatements, strategies, complexity notes, and worked walkthroughs.
  • Chores
    • Updated the problems manifest: simplified one entry and appended two new problem entries.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds many new explanation markdowns and Python solution implementations for assorted algorithm problems (linked lists, trees, graphs, greedy, backtracking, matrix/string utilities), plus updates to data/leetcode-problems.json that replace one entry and append two new problem entries.

Changes

Cohort / File(s) Summary
Explanation documents
explanations/237/en.md, explanations/2482/en.md, explanations/797/en.md, explanations/1008/en.md, explanations/1079/en.md, explanations/1261/en.md, explanations/1347/en.md, explanations/1551/en.md, explanations/1605/en.md, explanations/1630/en.md, explanations/1823/en.md, explanations/2110/en.md, explanations/2120/en.md, explanations/2221/en.md, explanations/2326/en.md, explanations/2785/en.md
Added multiple pedagogical markdowns describing problem restatements, constraints, algorithm strategies, complexity, decomposition steps, and worked examples for the listed problems.
Tree & graph solutions
solutions/1008/01.py, solutions/1261/01.py, solutions/797/01.py, solutions/2326/01.py, solutions/237/01.py
Added implementations: BST from preorder (iterative stack), recover contaminated tree with set-based lookup, all-paths DFS backtracking, spiral matrix filling from a linked list, and in-place linked-list node deletion (copy-next and bypass).
Greedy / Interval / Covering / Matrix
solutions/1326/01.py, solutions/1551/01.py, solutions/1605/01.py, solutions/2482/01.py
Added greedy algorithms: min taps (interval covering), minOperations for sequence balancing, restoreMatrix by greedy cell fills, and onesMinusZeros matrix using precomputed row/column counts.
Backtracking / Recurrence
solutions/1079/01.py, solutions/1823/01.py
Added backtracking tile-sequences counter and Josephus recurrence solution.
Array / String / Utility solutions
solutions/1347/01.py, solutions/1630/01.py, solutions/2110/01.py, solutions/2120/01.py, solutions/2221/01.py, solutions/2637/01.py, solutions/2785/01.py, solutions/3271/01.py
Added solutions for character-frequency transforms, arithmetic subarray checks, descent-period counting, instruction-suffix simulation on grid, triangular sum reduction, row-with-max-ones, vowel sorting, and chunked string hashing.
Data file updates
data/leetcode-problems.json
Replaced the object at key "3772" with a shorter standardized record and appended new entries for keys "797" and "1008".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Variety of independent solution files increases heterogeneity — each requires light correctness and edge-case checks.
  • Pay extra attention to:
    • solutions/2482/01.py (reported high complexity — verify row/col counting and sign math).
    • Tree/linked-list manipulation (solutions/1261/01.py, solutions/2326/01.py, solutions/237/01.py) for null/None handling and in-place mutations.
    • data/leetcode-problems.json structural change for key "3772" and the appended "797", "1008" entries (consistency with parsers).

Possibly related PRs

Poem

🐰 I hopped through files both new and bright,
Planted explanations, solutions in sight.
Greedy, graph, and string — I nibbled each line,
Spirals and stacks, every algorithm fine.
A tiny rabbit cheers — more puzzles to dine! 🍃

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The pull request title 'upd' is vague and non-descriptive, providing no meaningful information about the changeset. Replace 'upd' with a descriptive title that summarizes the main changes, such as 'Add solutions and explanations for multiple LeetCode problems' or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 298c7df and 3a99b0c.

📒 Files selected for processing (35)
  • data/leetcode-problems.json (1 hunks)
  • explanations/1008/en.md (1 hunks)
  • explanations/1079/en.md (1 hunks)
  • explanations/1261/en.md (1 hunks)
  • explanations/1347/en.md (1 hunks)
  • explanations/1551/en.md (1 hunks)
  • explanations/1605/en.md (1 hunks)
  • explanations/1630/en.md (1 hunks)
  • explanations/1823/en.md (1 hunks)
  • explanations/2110/en.md (1 hunks)
  • explanations/2120/en.md (1 hunks)
  • explanations/2221/en.md (1 hunks)
  • explanations/2326/en.md (1 hunks)
  • explanations/237/en.md (1 hunks)
  • explanations/2482/en.md (1 hunks)
  • explanations/2785/en.md (1 hunks)
  • explanations/797/en.md (1 hunks)
  • solutions/1008/01.py (1 hunks)
  • solutions/1079/01.py (1 hunks)
  • solutions/1261/01.py (1 hunks)
  • solutions/1347/01.py (1 hunks)
  • solutions/1551/01.py (1 hunks)
  • solutions/1605/01.py (1 hunks)
  • solutions/1630/01.py (1 hunks)
  • solutions/1823/01.py (1 hunks)
  • solutions/2110/01.py (1 hunks)
  • solutions/2120/01.py (1 hunks)
  • solutions/2221/01.py (1 hunks)
  • solutions/2326/01.py (1 hunks)
  • solutions/237/01.py (1 hunks)
  • solutions/2482/01.py (1 hunks)
  • solutions/2637/01.py (1 hunks)
  • solutions/2785/01.py (1 hunks)
  • solutions/3271/01.py (1 hunks)
  • solutions/797/01.py (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 15, 2025

Reviewer's Guide

Adds multiple LeetCode problem solutions in Python along with detailed English explanations for some of them, implementing standard algorithmic approaches for arrays, graphs, linked lists, trees, and greedy/DP-style problems.

Class diagram for FindElements binary tree recovery

classDiagram
  class TreeNode {
    +int val
    +TreeNode left
    +TreeNode right
  }

  class FindElements {
    -set values
    +FindElements(root: TreeNode)
    +recover(node: TreeNode, val: int)
    +find(target: int) bool
  }

  FindElements --> TreeNode : uses
Loading

File-Level Changes

Change Details Files
Add explanation documents for several LeetCode problems with high-level strategy, complexity, and walkthrough examples.
  • Document the row/column counting strategy for computing ones-minus-zeros difference matrices.
  • Describe DFS with backtracking to enumerate all paths from source to target in a DAG.
  • Explain O(1) linked-list node deletion when only the node pointer is given.
explanations/2482/en.md
explanations/797/en.md
explanations/237/en.md
Implement spiral filling of an m x n matrix from a linked list.
  • Initialize an m-by-n matrix with -1 placeholders.
  • Traverse the linked list while walking the matrix in spiral order using direction vectors and bounds checks.
  • Change direction whenever the next cell is out of bounds or already filled.
solutions/2326/01.py
Implement greedy interval-cover solution for minimum taps to water a garden.
  • Convert tap ranges into [left,right] intervals clipped to [0,n].
  • Sort intervals and greedily extend coverage from left to right, counting taps.
  • Detect and return -1 when coverage cannot be extended to the end.
solutions/1326/01.py
Construct a BST from preorder traversal using a monotonic stack.
  • Create the root from the first preorder value and maintain a stack of ancestors.
  • Attach each new node as a left child when its value is less than the stack top.
  • Pop until finding the appropriate parent for right children and attach accordingly.
solutions/1008/01.py
Recover contaminated binary tree values and support O(1) existence queries.
  • Traverse the tree assigning values based on 2i+1 and 2i+2 rules starting from 0.
  • Store all recovered values in a set during reconstruction.
  • Implement find() as a set membership check.
solutions/1261/01.py
Check if multiple subarrays can form arithmetic sequences after sorting.
  • For each query, slice nums by given l[i] and r[i] indices and sort the subarray.
  • Handle short subarrays as trivially arithmetic.
  • Verify constant differences between consecutive sorted values and collect boolean results.
solutions/1630/01.py
Compute ones-minus-zeros matrix using precomputed row/column counts.
  • Count ones per row and column in a first pass over the grid.
  • Derive zeros per row/column from dimensions and ones counts.
  • Fill result matrix using the formula ones_row[i]+ones_col[j]-zeros_row[i]-zeros_col[j].
solutions/2482/01.py
Sort vowels in a string while leaving consonants in place.
  • Collect all vowel characters from the string and sort them asc.
  • Iterate over original string, replacing vowel positions with the next sorted vowel.
  • Rebuild and return the transformed string.
solutions/2785/01.py
Use a greedy strategy with Fibonacci numbers to sum to k with minimal count.
  • Generate all Fibonacci numbers up to k.
  • Repeatedly subtract the largest Fibonacci number not exceeding the remaining k.
  • Count how many numbers are used until k becomes zero.
solutions/1551/01.py
Implement in-place deletion of a linked-list node without head pointer.
  • Copy the next node’s value into the current node.
  • Relink current node’s next to skip the next node.
solutions/237/01.py
Enumerate all paths from source to target in a DAG using DFS and backtracking.
  • Maintain a current path list during DFS starting from node 0.
  • When reaching node n-1, append a copy of the path to results.
  • Backtrack after exploring each neighbor to reuse the path list.
solutions/797/01.py
Count distinct non-empty sequences that can be formed from letter tiles using backtracking with frequency counts.
  • Use a Counter to track remaining counts of each tile character.
  • For each recursive call, try placing any available character, decrementing and then backtracking.
  • Accumulate the total count of all sequences formed.
solutions/1079/01.py
Find the champion team in a tournament matrix by scanning rows for dominance.
  • Iterate over each team’s row and check if it has 1s against all other teams.
  • Return the index of the first team that beats every other team, or -1 if none.
solutions/2221/01.py
Restore a non-negative matrix from given row and column sums via greedy allocation.
  • Initialize an m-by-n matrix of zeros.
  • For each cell, assign the minimum of remaining row and column sums and deduct it.
  • Return the filled matrix once all sums are exhausted.
solutions/1605/01.py
Compute minimum replacement operations to make two strings anagrams based on character deficits in t.
  • Count character frequencies for s and t with Counter.
  • For each character in s, sum positive excess over t’s count.
  • Return the total operations needed.
solutions/1347/01.py
Identify the row with the maximum number of ones in a binary matrix.
  • Iterate rows, summing elements to count ones.
  • Track the row index with the largest count and its value.
  • Return both as a pair [rowIndex, onesCount].
solutions/2637/01.py
Represent an integer as a sum of three consecutive integers when possible.
  • Use algebra to derive that num must be divisible by 3.
  • If divisible, compute center x=num/3 and return [x-1,x,x+1], else return empty list.
solutions/2120/01.py
Solve the Josephus problem variant to find the winner of a circular game.
  • Iteratively compute the safe position using 0-based recurrence res=(res+k) % i for i from 2 to n.
  • Convert final 0-based result to 1-based index before returning.
solutions/1823/01.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • In solutions/2482/01.py, zeros_row and zeros_col are recomputed inside the innermost loop for every cell; consider precomputing zeros_row and zeros_col arrays once after counting ones and then reusing them in the result-building loop to avoid redundant work.
  • In explanations/2482/en.md, the constraint bullet "matrix can have up to 10^5 rows and columns, with total cells up to 10^5" is internally inconsistent; it would be clearer to state that m and n are up to 10^5 with the product m * n bounded by 10^5.
  • In solutions/1630/01.py, you can avoid sorting for trivial subarrays by checking len(subarray) < 2 before calling subarray.sort(), which slightly reduces unnecessary work for very small ranges.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `solutions/2482/01.py`, `zeros_row` and `zeros_col` are recomputed inside the innermost loop for every cell; consider precomputing `zeros_row` and `zeros_col` arrays once after counting ones and then reusing them in the result-building loop to avoid redundant work.
- In `explanations/2482/en.md`, the constraint bullet "matrix can have up to 10^5 rows and columns, with total cells up to 10^5" is internally inconsistent; it would be clearer to state that `m` and `n` are up to 10^5 with the product `m * n` bounded by 10^5.
- In `solutions/1630/01.py`, you can avoid sorting for trivial subarrays by checking `len(subarray) < 2` before calling `subarray.sort()`, which slightly reduces unnecessary work for very small ranges.

## Individual Comments

### Comment 1
<location> `solutions/2482/01.py:19-21` </location>
<code_context>
+        res = [[0] * n for _ in range(m)]
+        for i in range(m):
+            for j in range(n):
+                zeros_row = n - ones_row[i]
+                zeros_col = m - ones_col[j]
+                res[i][j] = ones_row[i] + ones_col[j] - zeros_row - zeros_col
+
+        return res
</code_context>

<issue_to_address>
**suggestion (performance):** Avoid recomputing zeros_row/zeros_col inside the inner loop

Since `zeros_row` depends only on `i` and `zeros_col` only on `j`, avoid recomputing them for every cell. Either precompute per-row/per-column arrays, or use the equivalent formula:

```python
res[i][j] = 2 * ones_row[i] - n + 2 * ones_col[j] - m
```

This removes the extra subtractions and repeated work in the inner loop.
</issue_to_address>

### Comment 2
<location> `explanations/2482/en.md:14` </location>
<code_context>
+- **Input Size:** The matrix can have up to 10^5 rows and columns, with total cells up to 10^5.
+- **Time Complexity:** O(m*n) - We need to traverse the matrix twice: once to count ones in rows and columns, and once to build the result matrix.
+- **Space Complexity:** O(m + n) - We store arrays for row and column counts.
+- **Edge Case:** Empty matrix or single cell matrix are handled naturally by the algorithm.
+
+**1.2 High-level approach**
</code_context>

<issue_to_address>
**issue (typo):** Fix subject-verb agreement and phrasing in the edge case sentence.

You could rephrase to: "**Edge Case:** An empty matrix or a single-cell matrix is handled naturally by the algorithm." or "**Edge Case:** Empty or single-cell matrices are handled naturally by the algorithm."

```suggestion
- **Edge Case:** Empty or single-cell matrices are handled naturally by the algorithm.
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 11

🧹 Nitpick comments (6)
solutions/1347/01.py (1)

1-13: Correct minSteps logic; consider moving Counter import to module scope

The counting logic is correct and efficiently computes the minimal number of replacements.

For style/readability, you might move the import to the top of the file:

+from collections import Counter
+
 class Solution:
     def minSteps(self, s: str, t: str) -> int:
-        from collections import Counter
-
         count_s = Counter(s)
         count_t = Counter(t)
solutions/237/01.py (1)

1-17: Deletion logic is correct under LeetCode constraints

The copy-and-bypass approach is correct assuming node.next is not None (as per the original problem). If you ever reuse this outside that context, consider adding an assertion or guard around node/node.next to fail fast on invalid input.

explanations/237/en.md (2)

5-28: Consider using proper markdown headings for better structure.

The document uses bold text for subsection headers (e.g., Restate the problem, 1.1 Constraints & Complexity) instead of proper markdown headings. This affects document navigation and accessibility.

Apply this diff to use proper heading levels:

-**Restate the problem**
+#### Restate the problem

-**1.1 Constraints & Complexity**
+#### 1.1 Constraints & Complexity

-**1.2 High-level approach**
+#### 1.2 High-level approach

-**1.3 Brute force vs. optimized strategy**
+#### 1.3 Brute force vs. optimized strategy

-**1.4 Decomposition**
+#### 1.4 Decomposition

35-60: Consider using proper markdown headings for the Steps section.

Similar to the Strategy section, the Steps subsections use bold text instead of proper markdown headings.

Apply this diff:

-**2.1 Initialization & Example Setup**
+#### 2.1 Initialization & Example Setup

-**2.2 Start Processing**
+#### 2.2 Start Processing

-**2.3 Trace Walkthrough**
+#### 2.3 Trace Walkthrough

-**2.4 Update Pointers**
+#### 2.4 Update Pointers

-**2.5 Return Result**
+#### 2.5 Return Result
solutions/1079/01.py (1)

3-3: Consider moving import to module level.

Importing Counter inside the method works but is unconventional. Module-level imports are more idiomatic and improve readability.

Apply this diff to move the import:

+from collections import Counter
+
 class Solution:
     def numTilePossibilities(self, tiles: str) -> int:
-        from collections import Counter
-
         def backtrack(count):
explanations/2482/en.md (1)

5-75: Minor doc polish: hyphenation and heading style (optional)

The explanation is clear and technically accurate; only small style tweaks are suggested:

  • On Line 14, LanguageTool is right that “single cell matrix” should be hyphenated:
-- **Edge Case:** Empty matrix or single cell matrix are handled naturally by the algorithm.
+- **Edge Case:** Empty matrix or single-cell matrix are handled naturally by the algorithm.
  • markdownlint’s MD036 warnings come from using bold text as section labels (e.g., **Restate the problem**, **1.1 Constraints & Complexity**). If you want to satisfy the linter, you can convert these to proper headings, for example:
-**Restate the problem**
+#### Restate the problem

and similarly for the other bolded “section titles” (**1.1 Constraints & Complexity**, **1.2 High-level approach**, etc.).

These are cosmetic and can be applied whenever you next touch the doc.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c80678c and 298c7df.

📒 Files selected for processing (20)
  • explanations/237/en.md (1 hunks)
  • explanations/2482/en.md (1 hunks)
  • explanations/797/en.md (1 hunks)
  • solutions/1008/01.py (1 hunks)
  • solutions/1079/01.py (1 hunks)
  • solutions/1261/01.py (1 hunks)
  • solutions/1326/01.py (1 hunks)
  • solutions/1347/01.py (1 hunks)
  • solutions/1551/01.py (1 hunks)
  • solutions/1605/01.py (1 hunks)
  • solutions/1630/01.py (1 hunks)
  • solutions/1823/01.py (1 hunks)
  • solutions/2120/01.py (1 hunks)
  • solutions/2221/01.py (1 hunks)
  • solutions/2326/01.py (1 hunks)
  • solutions/237/01.py (1 hunks)
  • solutions/2482/01.py (1 hunks)
  • solutions/2637/01.py (1 hunks)
  • solutions/2785/01.py (1 hunks)
  • solutions/797/01.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
solutions/1551/01.py (1)
solutions/509/01.py (1)
  • fib (2-15)
solutions/1347/01.py (1)
solutions/1079/01.py (1)
  • Solution (1-16)
🪛 LanguageTool
explanations/237/en.md

[style] ~7-~7: Try using a synonym here to strengthen your writing.
Context: ...ode from a linked list, but we are only given access to the node to be deleted (not t...

(GIVE_PROVIDE)

explanations/2482/en.md

[grammar] ~14-~14: Use a hyphen to join words.
Context: ... - Edge Case: Empty matrix or single cell matrix are handled naturally by the...

(QB_NEW_EN_HYPHEN)

🪛 markdownlint-cli2 (0.18.1)
explanations/237/en.md

5-5: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


9-9: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


16-16: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


22-22: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


28-28: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


38-38: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


46-46: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


50-50: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

explanations/2482/en.md

5-5: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


9-9: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


16-16: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


22-22: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


28-28: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


38-38: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


46-46: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


50-50: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


62-62: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


66-66: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🪛 Ruff (0.14.8)
solutions/2637/01.py

2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)

solutions/1008/01.py

8-8: Undefined name List

(F821)


8-8: Undefined name Optional

(F821)


8-8: Undefined name TreeNode

(F821)


12-12: Undefined name TreeNode

(F821)


16-16: Undefined name TreeNode

(F821)

solutions/2120/01.py

2-2: Undefined name List

(F821)

solutions/2326/01.py

7-7: Undefined name Optional

(F821)


7-7: Undefined name ListNode

(F821)


7-7: Undefined name List

(F821)


7-7: Undefined name List

(F821)

solutions/1605/01.py

2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)

solutions/2482/01.py

2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)

solutions/2221/01.py

2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)

solutions/1326/01.py

2-2: Undefined name List

(F821)

solutions/797/01.py

2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)


2-2: Undefined name List

(F821)

solutions/1630/01.py

3-3: Undefined name List

(F821)


3-3: Ambiguous variable name: l

(E741)


3-3: Undefined name List

(F821)


3-3: Undefined name List

(F821)


4-4: Undefined name List

(F821)

solutions/1261/01.py

9-9: Undefined name Optional

(F821)


9-9: Undefined name TreeNode

(F821)

🔇 Additional comments (12)
solutions/1823/01.py (1)

1-8: Correct and efficient Josephus implementation

The iterative 0‑indexed recurrence and final + 1 conversion are correct, handle edge cases like n = 1 cleanly, and run in O(n) time / O(1) space. Looks good as a LeetCode solution.

solutions/1261/01.py (1)

7-23: FindElements recovery + lookup logic looks solid

DFS recovery with root = 0, left = 2*val+1, right = 2*val+2 and caching all values in a set gives O(n) preprocessing and O(1) find, and safely handles root is None. No issues with the core algorithm.

solutions/2785/01.py (1)

1-19: Vowel-sorting implementation is correct and clean

The algorithm correctly preserves consonant positions, sorts vowels (both cases), and reconstructs the string in a single pass; no issues spotted.

explanations/797/en.md (1)

1-68: DFS/backtracking explanation is clear and aligned with the typical solution

The write-up accurately restates the problem, matches the DFS + backtracking approach, and the example trace table clearly illustrates how all paths are enumerated.

solutions/1551/01.py (1)

1-17: Greedy Fibonacci decomposition is correct and efficient

Generating Fibonacci numbers up to k and then greedily subtracting the largest not exceeding the remainder is the right approach here; the implementation is clean and handles edge cases like k = 1 correctly.

solutions/1605/01.py (1)

6-12: LGTM! Greedy approach is correct.

The greedy algorithm correctly distributes values by taking the minimum of remaining row and column sums at each step, ensuring both constraints are satisfied.

solutions/2221/01.py (1)

6-13: LGTM! Champion detection logic is sound.

The algorithm correctly identifies a team that beats all others by checking for a row with all 1s except the diagonal.

solutions/1079/01.py (1)

5-13: LGTM! Backtracking logic is correct.

The algorithm correctly generates all distinct non-empty sequences by decrementing available counts, recursing, and backtracking.

solutions/1008/01.py (1)

15-27: LGTM! Stack-based BST construction is correct.

The iterative approach correctly constructs a BST by maintaining a stack of potential parents and attaching nodes based on BST properties.

solutions/1630/01.py (1)

7-23: LGTM! Arithmetic progression check is correct.

The algorithm correctly extracts each subarray, sorts it, and verifies that consecutive differences are constant.

solutions/2326/01.py (1)

16-38: LGTM! Spiral traversal logic is correct.

The algorithm correctly fills the matrix in spiral order by tracking direction and changing course when hitting boundaries or already-filled cells.

solutions/1326/01.py (1)

3-32: LGTM! Greedy interval covering is correct.

The algorithm correctly converts tap ranges to intervals and uses a greedy approach to find the minimum number of taps needed to cover [0, n].

Comment on lines +1 to +6
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cat -n solutions/1261/01.py

Repository: romankurnovskii/leetcode-apps

Length of output: 1020


Add missing Optional import and define or quote TreeNode type

Line 9 references Optional[TreeNode], but neither is available: Optional is not imported, and TreeNode is only in comments. This will break at import time and trigger Ruff F821.

For a standalone environment, define the node class and import Optional:

+from typing import Optional
+
 # Definition for a binary tree node.
-# class TreeNode:
-#     def __init__(self, val=0, left=None, right=None):
-#         self.val = val
-#         self.left = left
-#         self.right = right
+class TreeNode:
+    def __init__(self, val=0, left=None, right=None):
+        self.val = val
+        self.left = left
+        self.right = right

If this file is meant only for LeetCode submission where TreeNode is pre-defined, keep it commented but at minimum add from typing import Optional and use a string annotation: root: "Optional[TreeNode]" on line 9.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
from typing import Optional
# Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
🤖 Prompt for AI Agents
In solutions/1261/01.py around lines 1 to 6, the code references
Optional[TreeNode] but Optional is not imported and TreeNode is only in
comments; import Optional from typing and either define the TreeNode class
(uncomment/provide the class definition) or keep LeetCode's TreeNode commented
and change annotations to use a forward-ref string like root:
"Optional[TreeNode]"; ensure you add from typing import Optional at the top and
update any type hints accordingly so the file imports cleanly.

Comment on lines +1 to +2
class Solution:
def minTaps(self, n: int, ranges: List[int]) -> int:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add missing import for type hints.

The List type hint is used but not imported, which will cause a NameError at runtime if type hints are evaluated.

Apply this diff:

+from typing import List
+
 class Solution:
     def minTaps(self, n: int, ranges: List[int]) -> int:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class Solution:
def minTaps(self, n: int, ranges: List[int]) -> int:
from typing import List
class Solution:
def minTaps(self, n: int, ranges: List[int]) -> int:
🧰 Tools
🪛 Ruff (0.14.8)

2-2: Undefined name List

(F821)

🤖 Prompt for AI Agents
In solutions/1326/01.py around lines 1 to 2, the type hint List is referenced
but not imported; add the missing import by adding "from typing import List" (or
equivalent) at the top of the file so the List name is defined for the minTaps
method signature.

Comment on lines 1 to 4
class Solution:
def checkArithmeticSubarrays(
self, nums: List[int], l: List[int], r: List[int]
) -> List[bool]:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add missing import and consider renaming parameter.

Two issues:

  1. The List type hint is used but not imported (critical).
  2. The parameter name l is ambiguous per PEP 8 guidelines.

Apply this diff:

+from typing import List
+
 class Solution:
     def checkArithmeticSubarrays(
-        self, nums: List[int], l: List[int], r: List[int]
+        self, nums: List[int], left: List[int], right: List[int]
     ) -> List[bool]:
         res = []
 
-        for i in range(len(l)):
-            subarray = nums[l[i] : r[i] + 1]
+        for i in range(len(left)):
+            subarray = nums[left[i] : right[i] + 1]

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Ruff (0.14.8)

3-3: Undefined name List

(F821)


3-3: Ambiguous variable name: l

(E741)


3-3: Undefined name List

(F821)


3-3: Undefined name List

(F821)


4-4: Undefined name List

(F821)

🤖 Prompt for AI Agents
In solutions/1630/01.py around lines 1 to 4, the function uses the type hint
List but the module does not import it and the parameter named "l" is ambiguous;
add "from typing import List" at the top of the file and rename the parameter
"l" to a clearer name such as "left" (update all occurrences in the function
signature and body accordingly) so type checking works and the parameter name
follows PEP 8.

Comment on lines +6 to +7
class Solution:
def spiralMatrix(self, m: int, n: int, head: Optional[ListNode]) -> List[List[int]]:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add missing imports for type hints.

The type hints Optional, ListNode, and List are used but not imported, which will cause NameError at runtime if type hints are evaluated.

Apply this diff:

+from typing import List, Optional
+
 # Definition for singly-linked list.
 # class ListNode:
 #     def __init__(self, val=0, next=None):
 #         self.val = val
 #         self.next = next
+
 class Solution:
     def spiralMatrix(self, m: int, n: int, head: Optional[ListNode]) -> List[List[int]]:

Note: ListNode is typically defined elsewhere in LeetCode's environment, but ensure it's imported or defined if running outside that context.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class Solution:
def spiralMatrix(self, m: int, n: int, head: Optional[ListNode]) -> List[List[int]]:
from typing import List, Optional
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def spiralMatrix(self, m: int, n: int, head: Optional[ListNode]) -> List[List[int]]:
🧰 Tools
🪛 Ruff (0.14.8)

7-7: Undefined name Optional

(F821)


7-7: Undefined name ListNode

(F821)


7-7: Undefined name List

(F821)


7-7: Undefined name List

(F821)

🤖 Prompt for AI Agents
In solutions/2326/01.py around lines 6 to 7, the function signature uses type
hints Optional, ListNode, and List but those names are not imported; update the
file to import the missing typing symbols (e.g. from typing import Optional,
List) and ensure ListNode is available in this module (either import or define a
stub/class matching LeetCode's ListNode) so the annotations do not raise
NameError when evaluated.

@romankurnovskii romankurnovskii merged commit 0349164 into main Dec 15, 2025
3 of 4 checks passed
@romankurnovskii romankurnovskii deleted the problems-2482-1261-1008-1630-1079-2785-797-237-3271-2637-1605-1551-1347-2326-1823-2221-2120 branch December 15, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant